package cn.stronglink.assetmanage.business.check.view.sync;

import android.app.Dialog;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.view.View;
import android.widget.TextView;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import cn.stronglink.assetmanage.R;
import cn.stronglink.assetmanage.business.check.adapter.CheckOrderAdapter;
import cn.stronglink.assetmanage.business.check.view.CheckFragment;
import cn.stronglink.assetmanage.business.check.view.detail.CheckSyncDetailFragment;
import cn.stronglink.assetmanage.business.check.view.detail.CheckedDetailFragment;
import cn.stronglink.assetmanage.business.check.view.wait.WaitAssetFragment;
import cn.stronglink.assetmanage.entity.Asset;
import cn.stronglink.assetmanage.entity.Check;
import cn.stronglink.assetmanage.utils.Constants;
import cn.stronglink.assetmanage.utils.ToastUtil;
import cn.stronglink.assetmanage.widget.CustomProgressDialog;

/**
 * 待同步数据
 * Created by chencongcong on 2018/6/14.
 */

public class SyncAssetView {
    private Fragment fragment;
    //表单号
    @BindView(R.id.tv_checksync_order_name)
    TextView tv_checksync_order_name;
    //表单日期
    @BindView(R.id.tv_checksync_operation_date)
    TextView tv_checksync_operation_date;
    @BindView(R.id.tv_checksync_operation_date_1)
    TextView tv_checksync_operation_date_1;
    //资源列表adapter
    private CheckOrderAdapter orderAdapter;
    Dialog mDialog;

    public SyncAssetView(Fragment fragment, View view, CheckOrderAdapter orderAdapter) {
        this.fragment = fragment;
        ButterKnife.bind(this, view);
        this.orderAdapter = orderAdapter;
    }

    public void setOrderData(List<Asset> orderData) {
        if (orderAdapter != null) {
            orderAdapter.notifyDatasChanged(orderData);
        }
    }

    /**
     * 显示未入库资源列表表头
     */
    public void showAssetTitle(Check check) {
        if (check != null) {
            tv_checksync_order_name.setText(check.getId_());
            tv_checksync_operation_date.setText(check.getCreateTime());
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH-mm-ss");
            tv_checksync_operation_date_1.setText(sdf.format(new Date()));
        }
    }

    public void showWaitOrderDetail(Asset asset) {
        //跳转到详情页面
        Fragment detailFragment = new CheckSyncDetailFragment();
        FragmentManager fragmentManager = fragment.getActivity().getSupportFragmentManager();
        FragmentTransaction transaction = fragmentManager.beginTransaction();
        transaction.replace(R.id.frame_business, detailFragment);
        transaction.commit();
        Bundle bundle = new Bundle();
        bundle.putSerializable(Constants.CHECK_IN_DETAIL_NO, asset.getAsset_id_key());
        detailFragment.setArguments(bundle);
    }

    public void showProgressDialog(String msg) {
        mDialog = CustomProgressDialog.createLoadingDialog(fragment.getActivity(), msg);
        mDialog.setCancelable(false);
        mDialog.show();
    }

    public void hideProgressDialog() {
        if (mDialog != null) {
            mDialog.cancel();
        }
    }

    public void showToast(String msg) {
        ToastUtil.toastShort(msg);
    }

}
